class BaseScreen extends eui.Component {
	public constructor() {
		super();
	}

    protected sourceLoadOver:boolean = false;
    protected load_ok_hander:Function;
    protected load_start_hander:Function;
    protected is_loading:boolean = false;
    protected rect_bg:eui.Rect;
    protected is_start_mv:boolean = false;
    protected rect_to:eui.Rect;
    protected page_mode:string = '';
    protected xx_page:xxPage;
	protected childrenCreated(): void {
        super.childrenCreated();
        this.resize();

        if(this.rect_to){
            this.rect_to.addEventListener(egret.TouchEvent.TOUCH_TAP, this.rect_to_click, this);
        }
        
    }

	public resize():void
	{
		this.height=utils.CoreData.instance.screenH;
        if(this.rect_bg){
            if(this.height >1138){
                 this.rect_bg.height = this.height;
            }
            else{
                 this.rect_bg.height = 1138;
            }
        }

        if(this['img_bg']){
            if(this.height >1138){
                this['img_bg'].height = this.height;
            }
            else{
                 this['img_bg'].height = 1138;
            }
        }
        
	}

    public showPage(params = null) {
        egret.Tween.removeTweens(this);
        if (this.is_start_mv) {
            return;
        }
        this.is_start_mv = true;
    }

    public rect_to_click(){
        utils.ScreenManager.instance.main_screen.show_bm({page_mode:this.page_mode})
    }

    public initOldLayer(oldContainer:egret.DisplayObjectContainer,contentH:number):void
    {
        
    }

	public backOut(target:egret.DisplayObject,easeTime:number,offertX:number,offsetY:number,delayTime:number,callBack=null):void
    {

    }

    public cubicOut(target:egret.DisplayObject,easeTime:number,offertX:number,offsetY:number,delayTime:number,callBack=null):void
    {

    }

    public showSpeak(speak:eui.Group):void
    {

    }

	public dispose(): void {

	}

    //加载下一页的资源
    protected loadGradeSource(scene_name:string,start_hander:Function,load_end_hander:Function): void {
        if(this.is_loading)
            return;
        this.is_loading = true;
        console.log(`加载资源组`+scene_name);
        this.load_ok_hander = load_end_hander;
        RES.loadGroup(scene_name);
        RES.addEventListener(RES.ResourceEvent.GROUP_COMPLETE, this.onLoadResourceLoadComplete, this);
		RES.addEventListener(RES.ResourceEvent.GROUP_PROGRESS, this.onResourceProgress, this);
        RES.addEventListener(RES.ResourceEvent.GROUP_LOAD_ERROR,this.onLoadError, this);
        this.load_start_hander = start_hander;
        if(this.load_start_hander)
            this.load_start_hander();
    }
    //加载group结束
    protected onLoadResourceLoadComplete(event: RES.ResourceEvent): void {
        console.log(`资源组scene2加载结束`);
        this.sourceLoadOver = true;
        this.is_loading = false;
        RES.removeEventListener(RES.ResourceEvent.GROUP_COMPLETE, this.onLoadResourceLoadComplete, this);
		RES.removeEventListener(RES.ResourceEvent.GROUP_PROGRESS, this.onResourceProgress, this);
        RES.removeEventListener(RES.ResourceEvent.GROUP_LOAD_ERROR,this.onLoadError, this);
        if(this.load_ok_hander)
            this.load_ok_hander();
    }
    
    /**
     * preload资源组加载进度
     * loading process of preload resource
     */
	protected onResourceProgress(event: RES.ResourceEvent): void {
		// if (!this.group_loading.visible) return;
        // if(!this.processText) return;
		// this.processText.text = Math.floor(event.itemsLoaded * 100 / event.itemsTotal) + "%";
	}

    protected onLoadError(evt:RES.ResourceEvent):void{
        this.is_loading = false;
        RES.removeEventListener(RES.ResourceEvent.GROUP_COMPLETE, this.onLoadResourceLoadComplete, this);
		RES.removeEventListener(RES.ResourceEvent.GROUP_PROGRESS, this.onResourceProgress, this);
        RES.removeEventListener(RES.ResourceEvent.GROUP_LOAD_ERROR,this.onLoadError, this);
    }

    protected process(){
        
    }

    public anchorOff(dis:eui.UIComponent){
        dis.anchorOffsetX = dis.width*0.5;
        dis.anchorOffsetY = dis.height*0.5;
        dis.x += dis.width*0.5;
        dis.y += dis.height*0.5;
    }

    public out_page(){
        this.is_start_mv = false;
    }
}